<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>收货地址管理</title>
    <link rel="stylesheet" type="text/css" href="../css/common.css"/>
    <link rel="stylesheet" type="text/css" href="../css/main.css"/>
    <link rel="stylesheet" type="text/css" href="../css/bookManage.css"/>
    <script type="text/javascript" src="../js/modernizr.min.js"></script>
    <script type="text/javascript" src="../js/jquery-1.11.0.min.js"></script>
    <script type="text/javascript" src="../js/getParameter.js"></script>
    <script>
        $(function () {
            //调用公共header
            $('#left').load('left.html');
            $('#header').load('header.html');
        });
    </script>
    <script>
        //删除
        function delAddress(addressId) {
            // alert(bid);
            if (confirm("确定删除该条记录吗？")) {
                $.get("../address/delAddress", {addressId: addressId}, function (data) {
                    if (data.errorType == 0) {
                        alert(data.errorInfo);
                        location.reload();
                    } else {
                        alert(data.errorInfo);
                    }
                });
            }
        }

        function loadAddressManage(start, uid) {
            $.post("../address/getAddressByUid.do", {start: start, uid: uid}, function (data) {
                var trs = "<tr>\n" +
                    "                                <th>收货人&nbsp;&nbsp;</th>\n" +
                    "                                <th>电话号码&nbsp;&nbsp;</th>\n" +
                    "                                <th>收货地址&nbsp;&nbsp;</th>\n" +
                    "                                <th>操作&nbsp;&nbsp;</th>\n" +
                    "                            </tr>";
                if (data == null) {
                    alert("操作失败，您的权限不够。。。");
                } else { //权限合格  返回不为空有数据
                    for (var i = 0; i < data.list.length; i++) { //所有查出来的书籍集合
                        trs += "<tr>" +
                            "       <td>" + data.list[i].name + "</td>\n" +
                            "       <td>" + data.list[i].phone + "</td>\n" +
                            "       <td>" + data.list[i].address + "</td>\n" +
                            "       <td>" +
                            "           <a href='addressUpdate.html?addressId=" + data.list[i].addressId + "'>修改&nbsp;&nbsp;</a>" +
                            "           <a href='javascript:;' onclick='delAddress(" + data.list[i].addressId + ")'>删除&nbsp;&nbsp;</a>" +
                            "       </td>\n" +
                            "</tr>";
                    }
                    //表格页
                    $("#tb_address").html(trs);
                    //分页
                    var lis = "<li>\n" +
                        "                <a href=\"#\" aria-label=\"Previous\"  onclick='loadAddressManage(" + data.prePage + "," + uid + ")'>\n" +
                        "                    <span aria-hidden=\"true\">&laquo;</span>\n" +
                        "                </a>\n" +
                        "            </li>";
                    if (data.prePage == 0) {
                        lis = "<li class='disabled'>\n" +
                            "                <a href=\"#\" aria-label=\"Previous\">\n" +
                            "                    <span aria-hidden=\"true\">&laquo;</span>\n" +
                            "                </a>\n" +
                            "            </li>";
                    }
                    for (var i = 1; i <= data.lastPage; i++) {
                        lis += "<li><a href=\"#\"  onclick='loadAddressManage(" + i + "," + uid + ")'>" + i + "</a></li>";
                    }
                    //结尾
                    if (data.nextPage == 0) { //下一页大于最后一页时  按钮禁用
                        lis += "<li class='disabled'>\n" +
                            "                <a href=\"#\" aria-label=\"Next\" >\n" +
                            "                    <span aria-hidden=\"true\">&raquo;</span>\n" +
                            "                </a>\n" +
                            "            </li>";
                    } else {
                        lis += "<li>\n" +
                            "                <a href='#' onclick='loadAddressManage(" + data.nextPage + "," + uid + ")' aria-label=\"Next\">\n" +
                            "                    <span aria-hidden=\"true\">&raquo;</span>\n" +
                            "                </a>\n" +
                            "            </li>";
                    }
                    //生成
                    $("#pagination").html(lis);
                    $("#tips").html("当前第" + data.pageNum + "页，共" + data.pages + "页，" + data.total + "条数据");
                }
            });
        }

        //入口函数
        $(function () {
            //加载主体
            var uid = getParameter("uid");
            loadAddressManage(1, uid);
            $("#add_btn").attr("href","../static/addAddress.html?uid=" + uid);
        });
    </script>
</head>
<body>
<div class="container clearfix">
    <div id="header"></div>
    <div id="left"></div>
    <!--/sidebar-->
    <div class="main-wrap">
        <div class="crumb-wrap">
            <div class="crumb-list"><i class="icon-font"></i><a href="index.html">书籍管理</a>
            </div>
        </div>
        <div class="search-wrap">
            <!--nav 导航-->
            <div class="search-wrap">
                <div class="search-content">
                </div>
            </div>
            <!--正文 主体-->
            <div class="result-wrap">
                <form name="myform" id="myform" method="post">
                    <div class="result-title">
                        <div class="result-list">
                            <a href="../static/addAddress.html" id="add_btn"><i class="icon-font"></i>新增收货地址</a>
                        </div>
                    </div>
                    <div class="result-content">
                        <table class="table table-hover" id="tb_address">
                        </table>
                    </div>
                </form>
            </div>
        </div>
        <!--footer 页脚-->
        <div class="footer">
            <nav aria-label="Page navigation">
                <ul class="pagination" id="pagination">

                </ul>
            </nav>
            <p id="tips"></p>
        </div>
    </div>
</div>
</body>
</html>